// pages/me/me.js
// 获取应用实例
const app = getApp()
const $req = require('../../utils/req.js') //接口封装文件
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userScopeMode:true,
    userInfo: null,
    wxinfo:null,
    token:null,
    datalogins:''
  },
    /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this
    let userInfo = null
    let token = null
    let wxinfo= null
    token =  wx.getStorageSync('token')
    wxinfo =  wx.getStorageSync('wxinfo')
   let datalogins =  wx.getStorageSync('datalogins')
    wx.hideTabBar() //隐藏系统tabbar
    app.editTabbar(); // 全局方法：editTabbar()调用自定义组件底部导航栏
     //wx.getStorageSync({key:'userInfos'});
    userInfo =  wx.getStorageSync('userInfo')
    if(userInfo.LoginFromQYB==true){
      userInfo.nickname = datalogins.companyName+userInfo.nickname
    }
     _this.setData({
      wxinfo:wxinfo,
      userInfo:userInfo,
      token:token,
      userScopeMode:false,
     // datalogins:datalogins
    })

  },
  logins(e){
    wx.navigateTo({url: '../login/login'})
  },
      // 拨打电话
      ontel(e){
        let that = this
        let  token=  wx.getStorageSync('token')
        wx.request({
          url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
          data: {
            cmd: 'aboutme',
            token:token
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success (data) {
            console.log(data.data.DATA)
            wx.makePhoneCall({
              phoneNumber: data.data.DATA.Mobile,
            })
          }
        });
      },
  
  //登录
  login:function() {
    let _this =this
    wx.login({
      success (res) {
        console.log(res)
        wx.request({
          url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
          data: {
            code: res.code,
            cmd: 'wxlogin',
            officeid:1
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success (data) {
            if(data.STATUS='Success'){
              _this.setData({
                userScopeMode:false,
              })
              console.log(data.data.DATA.token)
              wx.setStorageSync('userInfo',data.data.DATA);
              wx.setStorageSync('userInfos', 1);
             wx.setStorageSync('token',data.data.DATA.token);
            }
          }
        });
      }
    })
  },
  toOtherPage(e) {
    let _this = this
    let url = e.currentTarget.dataset.url
    wx.navigateTo({url: url})
  },

onShow(e){
  let userInfo =  wx.getStorageSync('userInfo')
  if(!userInfo){
    wx.navigateTo({
      url: '../login/login',
    })
  }
}


})